package arithmetic;

import java.util.Scanner;

/**
 * HJ42 学英语
 * 描述
 * Jessi初学英语，为了快速读出一串数字，编写程序将数字转换成英文：
 *
 * 具体规则如下:
 * 1.在英语读法中三位数字看成一整体，后面再加一个计数单位。从最右边往左数，三位一单位，例如12,345 等
 * 2.每三位数后记得带上计数单位 分别是thousand, million, billion.
 * 3.公式：百万以下千以上的数 X thousand X, 10亿以下百万以上的数：X million X thousand X, 10 亿以上的数：X billion X million X thousand X. 每个X分别代表三位数或两位数或一位数。
 * 4.在英式英语中百位数和十位数之间要加and，美式英语中则会省略，我们这个题目采用加上and，百分位为零的话，这道题目我们省略and
 *
 * 下面再看几个数字例句：
 * 22: twenty two
 * 100:  one hundred
 * 145:  one hundred and forty five
 * 1,234:  one thousand two hundred and thirty four
 * 8,088:  eight thousand (and) eighty eight (注:这个and可加可不加，这个题目我们选择不加)
 * 486,669:  four hundred and eighty six thousand six hundred and sixty nine
 * 1,652,510:  one million six hundred and fifty two thousand five hundred and ten
 *
 * 说明：
 * 数字为正整数，不考虑小数，转化结果为英文小写；
 * 保证输入的数据合法
 * 关键字提示：and，billion，million，thousand，hundred。
 *
 * 数据范围：1≤n≤2000000
 *
 *
 * 输入描述：
 * 输入一个long型整数
 *
 * 输出描述：
 * 输出相应的英文写法
 *
 * 示例1
 * 输入：
 * 22
 * 复制
 * 输出：
 * twenty two
 */
public class TestHW42 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        // while (in.hasNextInt()) { // 注意 while 处理多个 case
        //     int a = in.nextInt();
        //     int b = in.nextInt();
        //     System.out.println(a + b);
        // }
        String str = in.nextLine();
        if (str.isEmpty())return;
        str = str.replaceAll(",", "");
        // char[] chs = str.toCharArray();
        int num = Integer.parseInt(str);
        String result = test(num, "");
        System.out.println(result);
    }

    //chs.len == 2
    public static String test(int num, String result) {
        result = "";
        if (num <= 20) {
            result = len1(num);
        } else if (num >= 21 && num <= 99) {
            int num1 = num % 10;
            int num2 = num - num1;
            if (num1 == 0) {
                result = len1(num2);
            } else {
                result = len1(num2) + " " + len1(num1);
            }
        } else if (num >= 100 && num <= 999) {
            int num1 = num % 100;
            int num2 = num / 100;
            if (num1 == 0) {
                result = len1(num2) + " hundred";
            } else {
                int num3 = num - num2 * 100;
                result = len1(num2) + " hundred and " + test(num3, "");
            }
        } else if (num >= 1000 && num <= 999999) {
            int num1 = num % 1000;
            int num2 = num / 1000;
            if (num1 == 0) {
                result = test(num2, "") + " thousand";
            } else {
                int num3 = num - num2 * 1000;
                result = test(num2, "") + " thousand " + test(num3, "");
            }
        } else if (num >= 1000000 && num <= 99999999) {
            int num1 = num % 1000000;
            int num2 = num / 1000000;
            if (num1 == 0) {
                result = test(num2, "") + " million";
            } else {
                int num3 = num - num2 * 1000000;
                result = test(num2, " ") + " million " + test(num3, "");
            }
        } else if (num >= 100000000) {
            int num1 = num % 100000000;
            int num2 = num / 100000000;
            if (num1 == 0) {
                result = test(num2, "") + " billion";
            } else {
                int num3 = num - num2 * 100000000;
                result = test(num2, " ") + " billion " + test(num3, "");
            }
        }

        return result;
    }

    public static String len1(int num) {
        String value = "";
        switch (num) {
            case 0:
                value = "zero";
                break;
            case 1:
                value = "one";
                break;
            case 2:
                value = "two";
                break;
            case 3:
                value = "three";
                break;
            case 4:
                value = "four";
                break;
            case 5:
                value = "five";
                break;
            case 6:
                value = "six";
                break;
            case 7:
                value = "seven";
                break;
            case 8:
                value = "eight";
                break;
            case 9:
                value = "nine";
                break;
            case 10:
                value = "ten";
                break;
            case 11:
                value = "eleven";
                break;
            case 12:
                value = "twelve";
                break;
            case 13:
                value = "thirteen";
                break;
            case 14:
                value = "fourteen";
                break;
            case 15:
                value = "fifteen";
                break;
            case 16:
                value = "sixteen";
                break;
            case 17:
                value = "seventeen";
                break;
            case 18:
                value = "eighteen";
                break;
            case 19:
                value = "nineteen";
                break;
            case 20:
                value = "twenty";
                break;
            case 30:
                value = "thirty";
                break;
            case 40:
                value = "forty";
                break;
            case 50:
                value = "fifty";
                break;
            case 60:
                value = "sixty";
                break;
            case 70:
                value = "seventy";
                break;
            case 80:
                value = "eighty";
                break;
            case 90:
                value = "ninety";
                break;
            default:
                break;
        }
        return value;
    }
}
